﻿/**
* Created by Administrator on 2017/4/14 0014.
*/

$(document).ready(function () {
    var typeId = getUrlParam(typeId);
    var RId = getUrlParam(RId);

    //初始化tabTitle
    $.ajax({
        url: "ashx/getReportTypeHandler.ashx",
        type: "GET",
        dataType: "json",
        success: function (data) {
            var tabTitle = "<ul class='def-tab-list'>";
            $.each(data, function (index, num) {
                //tabTitle += "<li><a href='?typeId=" + num["id"] + "'>" + num["name"] + "</a></li>";
                tabTitle += "<li class='def-tab-item'><a onclick=getTopN(" + num["id"] + ")>" + num["name"] + "</a></li>";
            })
            tabTitle += "</ul>";
            $("#tabTitle").append(tabTitle);
            $("#tabTitle ul li a").eq(0).css("background", "#0099ff");
            $("#tabTitle ul li a").eq(0).css("color", "#ffffff");0
        }
    });
    //初始化前3
    $.ajax({
        url: "ashx/getTopNReportHandler.ashx?typeId=1",
        type: "GET",
        dataType: "json",
        success: function (data) {
            var top = "<ul class='def-tab-group'>";
            $.each(data, function (index, num) {
                if (index == 0) {
                    top += "<li class='def-group-item first'><a onclick=getCommentByRId(" + num["id"] + ") >" + num["name"] + "</a></li>";
                }
                if (index == 1) {
                    top += "<li class='def-group-item second'><a onclick=getCommentByRId(" + num["id"] + ") >" + num["name"] + "</a></li>";
                }
                if (index == 2) {
                    top += "<li class='def-group-item third'><a onclick=getCommentByRId(" + num["id"] + ") >" + num["name"] + "</a></li>";
                }
            })
            top += "</ul>";
            $("#top").empty();
            $("#top").append(top);
            //$("#top ul li a").eq(0).css("border-bottom", "2px solid #0099ff");
        }
    });
    //初始化评论
    $.ajax({
        url: "ashx/getCommentByRIdHandler.ashx?RId=29206",
        type: "GET",
        dataType: "json",
        success: function (data) {
            var content = "<ul class='def-cont-says'>";
            $.each(data, function (index, num) {
                content += "<li><img class='def-says-pic' src='image/pic1.jpg'><span class='def-says-txt'>" + num["content"] + "</span></li>";
            })
            content += "</ul>";
            $("#plcontent").empty();
            $("#plcontent").append(content);
        }
    });
    var typeId = getUrlParam("typeId");
    //初始化表格
    $.ajax({
        url: "ashx/TongjiHandler.ashx?typeId=1",
        type: "GET",
        dataType: "json",
        success: function (data) {
            var typeArr = new Array();
            var numArr = new Array();
            $.each(data, function (i, n) {
                typeArr[i] = n["Name"];
                numArr[i] = n["Num"];
            })
            //            alert(typeArr);
            //            alert(numArr);
            //var arr=["诈骗电话","骚扰电话","对我进行人身攻击","推销假货","诈骗短信","传销","中介"]
            var myChart1 = echarts.init(document.getElementById('jbtype1'));
            var option = {
                tooltip: {//提示框
                    show: true
                },
                legend: {//图例
                    data: ['举报类型人数']
                },
                xAxis: [
                    {
                        type: 'value'
                    }
                ],
                yAxis: [{
                    type: 'category',
                    data: typeArr
                }],
                series: [//设置数据
                    {
                    itemStyle: {
                        normal: {
                            color: function (params) {
                                var colorList = ['#ff7241', '#ffd011', '#71cffe', '#40d041', '#aa7941',
                                        '#7170ff', '#d0a0ff'];
                                return colorList[params.dataIndex]
                            }
                        }
                    },
                    "name": "举报类型人数",
                    "type": "bar",
                    "data": numArr
                }
                ]
            };
            //为myCharts对象加载数据
            myChart1.setOption(option);
        }
    });
    //初始化地图
    $.ajax({
        url: "ashx/ReportTongJiTotalTypeHandler.ashx?typeId=1",
        type: "GET",
        dataType: "json",
        success: function (data) {
            //alert(data);
            var maxValue=100;
            $.each(data, function (i, n) {
                if (n["value"] > maxValue) {
                    maxValue = n["value"];
                }
            });
            maxValue = Math.floor(maxValue / 100) * 100;
            var myChart2 = echarts.init(document.getElementById('jbMap'));
            option2 = {
                tooltip: {
                    tigger: 'item'
                },
                legend: {
                    orient: 'vertical', //布局方式
                    x: 'left', //水平安放位置
                    data: ['举报地区分布人数']
                },
                dataRange: {
                    min: 0,
                    max: maxValue,
                    x: 'left',
                    y: 'bottom',
                    text: ['高', '低'],
                    calculable: true,
                    color: ['#a50026','#bf444c','#bf444c', '#d73027', '#f46d43', '#fdae61', '#fee090', '#ffffbf', '#e0f3f8']
                },
                toolbox: {
                    show: true,
                    orient: 'vertical',
                    x: 'right',
                    y: 'center'
                },
                roamController: {
                    show: true,
                    x: 'right',
                    mapTypeControl: {
                        'china': true
                    }
                },
                series: [
                        {
                            name: '举报地区分布人数',
                            type: 'map',
                            mapType: 'china',
                            roam: false, //是否开启滚轮缩放和拖拽漫游
                            itemStyle: {
                                normal: {
                                    label: { show: true },
                                    borderWidth: 2,
                                    borderColor: '#ddd'
                                }, //默认样式
                                emphasis: { label: { show: true}}//强调样式
                            },
                            data: data
                        }
                    ]
            };
            //为myCharts对象加载数据
            myChart2.setOption(option2);
        }
    });

    //根据typeId显示前3，并显示第一的评论
    $.ajax({
        url: "ashx/getTopNReportHandler.ashx?typeId=" + typeId,
        type: "GET",
        dataType: "json",
        success: function (data) {
            //$("#top").empty();
            var top = "<ul class='def-tab-group'>";
            $.each(data, function (index, num) {
                //                if (index == 0) {
                //                    top += "<li class='def-group-item first' onclick=getTopN(" + num["id"] + ")>" + num["name"] + "</a></li>";
                //                }
                //                if (index == 1) {
                //                    top += "<li class='def-group-item second' onclick=getTopN(" + num["id"] + ")>" + num["name"] + "</a></li>";
                //                }
                //                if (index == 2) {
                //                    top += "<li class='def-group-item third' onclick=getTopN(" + num["id"] + ")>" + num["name"] + "</a></li>";
                //                }
                top += "<li><a onclick=getTopN(" + num["id"] + ")>" + num["name"] + "</a></li>";
                if (index == 0) {//判断是第一，显示评论
                    $.ajax({
                        url: "ashx/getCommentByRIdHandler.ashx?RId=" + num["id"],
                        type: "GET",
                        dataType: "json",
                        success: function (data) {
                            $("#plcontent").html("");
                            var content = "<ul class='def-cont-says'>";
                            $.each(data, function (index, num) {
                                content += "<li><img class='def-says-pic' src='image/pic1.jpg'><span class='def-says-txt'>" + num["content"] + "</span></li>";
                            })
                            content += "</ul>";
                            $("#plcontent").empty();
                            $("#plcontent").html(content);
                        }
                    });
                }
            })
            top += "</ul>";
            $("#top").empty();
            $("#top").append(top);
        }
    });

    //根据RId显示评论
    $.ajax({
        url: "ashx/getCommentByRIdHandler.ashx?RId=" + RId,
        type: "GET",
        dataType: "json",
        success: function (data) {
            var content = "<ul class='def-cont-says'>";
            $.each(data, function (index, num) {
                content += "<li><img class='def-says-pic' src='image/pic1.jpg'><span class='def-says-txt'>" + num["content"] + "</span></li>";
            })
            content += "</ul>";
            $("#plcontent").empty();
            $("#plcontent").html(content);
        }
    });
});

function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}

function getTopN(typeId) {
    $("#tabTitle ul li a").each(function(){
        $(this).css("background", "#ffffff");
        $(this).css("color", "#0099ff");
    })
    $("#tabTitle ul li a").eq(typeId - 1).css("background", "#0099ff");
    $("#tabTitle ul li a").eq(typeId - 1).css("color", "#ffffff");
    //前三
    $.ajax({
        url: "ashx/getTopNReportHandler.ashx?typeId=" + typeId,
        type: "GET",
        dataType: "json",
        success: function (data) {
            var top = "<ul class='def-tab-group'>";
            $.each(data, function (index, num) {
                if (index == 0) {
                    top += "<li class='def-group-item first'><a onclick=getCommentByRId(" + num["id"] + ") >" + num["name"] + "</a></li>";
                }
                if (index == 1) {
                    top += "<li class='def-group-item second'><a onclick=getCommentByRId(" + num["id"] + ") >" + num["name"] + "</a></li>";
                }
                if (index == 2) {
                    top += "<li class='def-group-item third'><a onclick=getCommentByRId(" + num["id"] + ") >" + num["name"] + "</a></li>";
                }
                //                top += "<li><a onclick=getCommentByRId(" + num["id"] + ") >" + num["name"] + "</a></li>";
                if (index == 0) {
                    getCommentByRId(num["id"]);
                }
            })
            top += "</ul>";
            $("#top").empty();
            $("#top").append(top);
        }
    });
    //表格
    $.ajax({
        url: "ashx/TongjiHandler.ashx?typeId=" + typeId,
        type: "GET",
        dataType: "json",
        success: function (data) {
            var typeArr = new Array();
            var numArr = new Array();
            $.each(data, function (i, n) {
                typeArr[i] = n["Name"];
                numArr[i] = n["Num"];
            })
//            alert(typeArr);
//            alert(numArr);
            var myChart1 = echarts.init(document.getElementById('jbtype1'));
            var option = {
                tooltip: {//提示框
                    show: true
                },
                legend: {//图例
                    data: ['举报类型人数']
                },
                xAxis: [
                    {
                        type: 'value'
                    }
                ],
                yAxis: [{
                    type: 'category',
                    data: typeArr
                }],
                series: [//设置数据
                    {
                    itemStyle: {
                        normal: {
                            color: function (params) {
                                var colorList = ['#ff7241', '#ffd011', '#71cffe', '#40d041', '#aa7941',
                                        '#7170ff', '#d0a0ff'];
                                return colorList[params.dataIndex]
                            }
                        }
                    },
                    "name": "举报类型人数",
                    "type": "bar",
                    "data": numArr
                }
                ]
            };
            //为myCharts对象加载数据
            myChart1.setOption(option);
        }
    });
    //地图
    $.ajax({
        url: "ashx/ReportTongJiTotalTypeHandler.ashx?typeId=" + typeId,
        type: "GET",
        dataType: "json",
        success: function (data) {
            //alert(data);
            var maxValue = 100;
            $.each(data, function (i, n) {
                if (n["value"] > maxValue) {
                    maxValue = n["value"];
                }
            });
            maxValue = Math.floor(maxValue / 100) * 100;
            var myChart2 = echarts.init(document.getElementById('jbMap'));
            option2 = {
                tooltip: {
                    tigger: 'item'
                },
                legend: {
                    orient: 'vertical', //布局方式
                    x: 'left', //水平安放位置
                    data: ['举报地区分布人数']
                },
                dataRange: {
                    min: 0,
                    max: maxValue,
                    x: 'left',
                    y: 'bottom',
                    text: ['高', '低'],
                    calculable: true,
                    color: ['#a50026', '#d73027', '#f46d43', '#fdae61', '#fee090', '#ffffbf', '#e0f3f8']
                },
                toolbox: {
                    show: true,
                    orient: 'vertical',
                    x: 'right',
                    y: 'center'
                },
                roamController: {
                    show: true,
                    x: 'right',
                    mapTypeControl: {
                        'china': true
                    }
                },
                series: [
                        {
                            name: '举报地区分布人数',
                            type: 'map',
                            mapType: 'china',
                            roam: false, //是否开启滚轮缩放和拖拽漫游
                            itemStyle: {
                                normal: {
                                    label: { show: true },
                                    borderWidth: 2,
                                    borderColor: '#ddd'
                                }, //默认样式
                                emphasis: { label: { show: true}}//强调样式
                            },
                            data: data
                        }
                    ]
            };
            //为myCharts对象加载数据
            myChart2.setOption(option2);
        }
    });
}

function getCommentByRId(RId) {
    //评论
    $.ajax({
        url: "ashx/getCommentByRIdHandler.ashx?RId=" + RId,
        type: "GET",
        dataType: "json",
        success: function (data) {
            var content = "<ul class='def-cont-says'>";
            $.each(data, function (index, num) {
                content += "<li><img class='def-says-pic' src='image/pic1.jpg'><span class='def-says-txt'>" + num["content"] + "</span></li>";
            })
            content += "</ul>";
            $("#plcontent").empty();
            $("#plcontent").append(content);
        }
    });
}
